package com.base.commonlib.widget;

import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AlertDialog;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.base.commonlib.R;


/**
 * Created by arvin on 2018/8/22.
 */

public class CommonDialog extends AlertDialog {

    private TextView mTv_title;
    private TextView mTv_content;
    private TextView mTv_neg;
    private TextView mTv_pos;
    private String mTitle;
    private CharSequence mContent;
    private String mNeg;
    private String mPos;
    private OnNegClick mOnNegClick;
    private OnPosClick mOnPosClick;


    public void setOnNegClick(OnNegClick onNegClick)
    {
        mOnNegClick=onNegClick;
    }

    public void setOnPosClick(OnPosClick onPosClick)
    {
        mOnPosClick=onPosClick;
    }

    public CommonDialog(@NonNull Context context, String content) {
        super(context, R.style.dialog);
        mContent=content;
    }

    public CommonDialog(@NonNull Context context, CharSequence content, String title, String neg, String pos) {
        super(context, R.style.dialog);
        mContent=content;
        mTitle=title;
        mNeg=neg;
        mPos=pos;

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.common_dialog_layout);
        mTv_title = findViewById(R.id.tv_title);
        mTv_content = findViewById(R.id.tv_content);
        mTv_neg = findViewById(R.id.tv_neg);
        mTv_pos = findViewById(R.id.tv_pos);
        if(!TextUtils.isEmpty(mTitle))
        {
            mTv_title.setText(mTitle);
        }
        if(!TextUtils.isEmpty(mContent))
        {
            mTv_content.setText(mContent);
        }
        if(!TextUtils.isEmpty(mNeg))
        {
            mTv_neg.setText(mNeg);
        }
        if(!TextUtils.isEmpty(mPos))
        {
            mTv_pos.setText(mPos);
        }
        mTv_neg.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if(mOnNegClick!=null)
                {
                    mOnNegClick.onClick();
                }

            }
        });
        mTv_pos.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if(mOnPosClick!=null)
                {
                    mOnPosClick.onClick();
                }

            }
        });
    }

    public interface OnNegClick
    {
        void onClick();
    }

    public interface OnPosClick
    {
        void onClick();
    }
}
